package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.TourismPlan;

public class TourismPlanDAOImpl extends BaseHibernateDAOImpl<TourismPlan> implements TourismPlanDAO {

	public TourismPlan getTourismPlanByTourismPlanID(String tpID) {
		TourismPlan tourismPlan;
		try {
			tourismPlan = (TourismPlan) getSession().get(TourismPlan.class, tpID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return tourismPlan;
	}

	@SuppressWarnings("unchecked")
	public List<TourismPlan> getAllTourismPlanByCondition(String hql) {
		List<TourismPlan> tourismPlans;
		try {
			Query query = getSession().createQuery("from TourismPlan" + hql);
			tourismPlans = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return tourismPlans;
	}

	@SuppressWarnings("unchecked")
	public List<TourismPlan> getAllTourismPlanByConditionByPage(String hql, int currentPage, int lineSize) {
		List<TourismPlan> tourismPlans;
		try {
			Query query = getSession().createQuery("from TourismPlan" + hql);
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			tourismPlans = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return tourismPlans;
	}

}
